/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_LABELBMFONT_IMPL__
#define __CC_PYTHON_IMPORT_O_LABELBMFONT_IMPL__

#include "python_object_labelbmfont.h"
#include "python_object_texture2d.h"

NS_CCPY_BEGIN
	CCNODE_OBJECT_WRAPPER_IMPL(CCLabelBMFont, CPyLabelBMFont)	

	PYCLASS_INIT_AND_BASE_3(CPyLabelBMFont, CPySpriteBatchNode, CPyLabelProtocol, CPyRGBAProtocol, "CCLabelBMFont", "Python CCLabelBMFont Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyLabelBMFont)
		PYCLASS_ADD_METHOD_EX(CPyLabelBMFont, initWithString, METH_KEYWORDS|METH_VARARGS)
		PYCLASS_ADD_METHOD(CPyLabelBMFont, createFontChars)
		PYCLASS_ADD_METHOD(CPyLabelBMFont, updateLabel)
	PYCLASS_END_METHOD_DEF(CPyLabelBMFont)
	PYCLASS_BEGIN_GETSET_DEF(CPyLabelBMFont)
		PYCLASS_ADD_SET(CPyLabelBMFont, Alignment)
		PYCLASS_ADD_SET(CPyLabelBMFont, Width)
		PYCLASS_ADD_SET(CPyLabelBMFont, LineBreakWithoutSpace)
		PYCLASS_ADD_SET(CPyLabelBMFont, FntFile)
	PYCLASS_END_GETSET_DEF(CPyLabelBMFont)
	PYCLASS_IMP_INTERFACE_NOINIT(CPyLabelBMFont)
	
	int CPyLabelBMFont::__init__(CPyLabelBMFont *pySelf, PyObject *args, PyObject *kwds)
	{
		if( !args )
			return 0;
		static char* kwlist[] = {"string", "fntFile", "width", "alignment", "imageOffset", NULL};
		char *string = NULL;
		char *fntFile = NULL;
		float width = -1;
		int align = static_cast<int>(cocos2d::kCCTextAlignmentLeft);
		PyObject *offset = NULL;
		if (!PyArg_ParseTupleAndKeywords(args,kwds,"|ssfiO", kwlist, &string, &fntFile, &width, &align, &offset))
			return 0;
		if(!string || !fntFile)
			return 0;
		cocos2d::CCLabelBMFont *spr = dynamic_cast<cocos2d::CCLabelBMFont *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		cocos2d::CCPoint pt = cocos2d::CCPointZero;
		if(offset && PyObject_TypeCheck(offset, CPyClassBase::GetTypeObject<CPyPoint>()))
			pt = ((CPyPoint *)offset)->getCCObject();
		
		spr->initWithString(string, fntFile, width, static_cast<cocos2d::CCTextAlignment>(align), pt);		
		return 0;
	}
	
	PYCLASS_METHOD_KW_IMPL(CPyLabelBMFont, initWithString)
	{
		if( !pyArgs )
			Py_RETURN_FALSE;
		static char* kwlist[] = {"string", "fntFile", "width", "alignment", "imageOffset", NULL};
		char *string = NULL;
		char *fntFile = NULL;
		float width = -1;
		int align = static_cast<int>(cocos2d::kCCTextAlignmentLeft);
		PyObject *offset = NULL;
		if (!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"|ssfiO", kwlist, &string, &fntFile, &width, &align, &offset))
			Py_RETURN_FALSE;
		if(!string || !fntFile)
			Py_RETURN_FALSE;
		cocos2d::CCLabelBMFont *spr = dynamic_cast<cocos2d::CCLabelBMFont *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_FALSE;
		cocos2d::CCPoint pt = cocos2d::CCPointZero;
		if(offset && PyObject_TypeCheck(offset, CPyClassBase::GetTypeObject<CPyPoint>()))
			pt = ((CPyPoint *)offset)->getCCObject();
		
		Py_RETURN_BOOL(spr->initWithString(string, fntFile, width, static_cast<cocos2d::CCTextAlignment>(align), pt));
		
	}
	
	PYCLASS_METHOD_IMPL(CPyLabelBMFont, createFontChars)
	{
		cocos2d::CCLabelBMFont *spr = dynamic_cast<cocos2d::CCLabelBMFont *>(pySelf->getCCObject());
		spr->createFontChars();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyLabelBMFont, updateLabel)
	{
		cocos2d::CCLabelBMFont *spr = dynamic_cast<cocos2d::CCLabelBMFont *>(pySelf->getCCObject());
		spr->updateLabel();
		Py_RETURN_NONE;
	}

	PYCLASS_SET_IMPL(CPyLabelBMFont, Alignment)
	{
		cocos2d::CCLabelBMFont *spr = dynamic_cast<cocos2d::CCLabelBMFont *>(pySelf->getCCObject());
		spr->setAlignment(static_cast<cocos2d::CCTextAlignment>(PyLong_AsLong(pyValue)));
		return 0;
	}

	PYCLASS_SET_IMPL(CPyLabelBMFont, Width)
	{
		cocos2d::CCLabelBMFont *spr = dynamic_cast<cocos2d::CCLabelBMFont *>(pySelf->getCCObject());
		spr->setWidth(PyFloat_AsDouble(pyValue));
		return 0;
	}

	PYCLASS_SET_IMPL(CPyLabelBMFont, LineBreakWithoutSpace)
	{
		cocos2d::CCLabelBMFont *spr = dynamic_cast<cocos2d::CCLabelBMFont *>(pySelf->getCCObject());
		spr->setLineBreakWithoutSpace(pyValue == Py_True);
		return 0;
	}

	PYCLASS_SET_IMPL(CPyLabelBMFont, FntFile)
	{
		cocos2d::CCLabelBMFont *spr = dynamic_cast<cocos2d::CCLabelBMFont *>(pySelf->getCCObject());
		spr->setFntFile(PyString_AsString(pyValue));
		return 0;
	}

NS_CCPY_END

#endif